package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {

    //注入service
    @Autowired
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        //单表使用IService 的list 方法
        List<PaymentType> list = paymentTypeService.list();
        //将list放到Result.ok()中
        Result<List<PaymentType>> result = Result.ok(list);
        //返回result即可
        return result;
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        //单表 直接使用IService的 saveOrUpdate 方法
        boolean is = paymentTypeService.saveOrUpdate(paymentType);
        //判断是否成功
        if (!is){
            //失败返回
            return Result.fail();
        }
        //成功返回正常成功
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        //单表使用IService 的removeById 方法
        paymentTypeService.removeById(id);
        //返回正确结果
        return Result.ok();
    }

}















